package com.example.insurance_service.controller;

import com.example.insurance_service.config.AjaxResult;
import com.example.insurance_service.domain.Insurance;
import com.example.insurance_service.service.InsuranceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("insurance")
@Api("保险订单Controller")
public class InsuranceController {

    @Autowired
    private InsuranceService insuranceService;

    @RequestMapping("getList")
   @ApiOperation(value = "查询",notes = "查询参数")
    public AjaxResult getList(@RequestParam(defaultValue = "1")Integer pageNum, @RequestParam(defaultValue = "3")Integer pageSize, Insurance insurance){
        Page<Insurance>info= insuranceService.findAll(pageNum,pageSize,insurance);
        System.err.println(info.getContent());
        return AjaxResult.ok(info);
    }

    /*添加*/
    @PostMapping("addInsurance")
    public AjaxResult addInsurance(@RequestBody Insurance insurance){
        boolean b=insuranceService.save(insurance);
        if (b){
            return AjaxResult.err(200,"成功");
        }else{
            return AjaxResult.err(400,"失败");
        }
    }

    /*删除*/
    @PostMapping("del")
    public AjaxResult del(@RequestBody Insurance insurance){
        insuranceService.delete(insurance);
        return AjaxResult.ok(200);
    }
}
